// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
// 全量引入 bk-magic-vue
import bkMagic from 'bk-magic-vue'
// 全量引入 bk-magic-vue 样式
import 'bk-magic-vue/dist/bk-magic-vue.min.css'
// 全局变量引入vue-resource
import VueResource from 'vue-resource'
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(bkMagic)
Vue.use(VueResource, VueResource)
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

Vue.config.productionTip = false
Vue.use(VueAxios, axios)
// 这里是添加的部分
function getCsrftokenByCookie () {
  const cookie = document.cookie.split(';')
  // 获取csrftoken
  let csrftoken = ''
  for (const i in cookie) {
    if (cookie[i].indexOf('csrftoken') !== -1) {
      csrftoken = cookie[i].split('=')[1]
    }
  }
  return csrftoken
}
// 每次请求头都带上我们的X-CSRFToken 信息
VueResource.defaults.headers.common['X-CSRFToken'] = getCsrftokenByCookie()
VueResource.defaults.withCredentials = true
Vue.config.productionTip = false
VueResource.defaults.baseURL = 'http://dev.paas-class.bktencent.com:8000/'

new Vue({
  render: h => h(App)
}).$mount('#app')
